package jms.producer;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;

public class JmsProducer {
	
	public static void main(String[] args) throws JMSException, InterruptedException {
		
		ActiveMQConnectionFactory aConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
		ConnectionFactory connectionFactory = aConnectionFactory;
		Connection conn = connectionFactory.createConnection();
		Destination queue =  new ActiveMQQueue("test");
		conn.start();
		Session session = conn.createSession(true,Session.AUTO_ACKNOWLEDGE);
		MessageProducer producer = session.createProducer(queue);
		for(int i=0;i<2000;i++){
			TextMessage message = new ActiveMQTextMessage();
			message.setText("hello"+i);
			producer.send(message);
//			Thread.sleep(1000);
		}
		
//		TextMessage message2 = new ActiveMQTextMessage();
//		message2.setText("hahhah");
//		producer.send(message2);
		session.commit();
		session.close();
		conn.close();
	}

}
